const db = require('./db');

async function checkData() {
  try {
    // 检查分类表数据
    console.log('检查分类表数据...');
    const categories = await db.promiseQuery('SELECT * FROM categories');
    console.log(`分类表中有 ${categories.length} 条数据:`);
    categories.forEach(cat => {
      console.log(`- ID: ${cat.id}, 名称: ${cat.name}`);
    });

    // 检查教材表数据
    console.log('\n检查教材表数据...');
    const textbooks = await db.promiseQuery('SELECT id, title, author, price, status FROM textbooks');
    console.log(`教材表中有 ${textbooks.length} 条数据:`);
    textbooks.forEach(book => {
      console.log(`- ID: ${book.id}, 标题: ${book.title}, 作者: ${book.author}, 价格: ¥${book.price}, 状态: ${book.status}`);
    });

    // 特别检查在售教材数量
    const onSaleTextbooks = await db.promiseQuery('SELECT COUNT(*) as count FROM textbooks WHERE status = ?', ['on_sale']);
    console.log(`\n在售教材数量: ${onSaleTextbooks[0].count}`);

  } catch (error) {
    console.error('检查数据时出错:', error);
  }
}

checkData();